package com.javafactroy.kunlong.framework.generalthread.base;

import com.javafactroy.kunlong.client.feign.dto.ApiResult;
import com.javafactroy.kunlong.framework.generalthread.iface.IgeneralRunner;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

@Slf4j
public class GeneralFutureTask<T> implements Callable<ApiResult<List<T>>> {
    List<T> data;

    IgeneralRunner<T> runner;
    CountDownLatch countDownLatch;

    public GeneralFutureTask(List<T> data, IgeneralRunner<T> runner, CountDownLatch c) {
        this.data = data;
        countDownLatch = c;
        this.runner = runner;
    }

    @Override
    public ApiResult<List<T>> call() throws Exception {
        ApiResult<List<T>> apiResult = runner.exec(data);
        log.info("data={}", data);

        countDownLatch.countDown();
        return apiResult;
    }
}
